<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld" %>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld" %>
<c:set var="BasePath" value="${pageContext.request.contextPath}">
</c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins">
</c:set>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>单据类型设置</title>
        <link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
        <script src="${Plugins}/jquery/jquery-1.3.2.min.js" type="text/javascript">
        </script>
        <script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript">
        </script>
        <script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript">
        </script>
        <script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript">
        </script>
        <script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript">
        </script>
        <script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript">
        </script>
        <script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
        <link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js">
        </script>
        <style type="text/css">
            
            .inputsize {
                width: 60px;
            }
            
            #searchbar {
                margin-bottom: 10px;
            }
            
            .navbar {
                height: 20px;
                border-bottom: #E6E6E6 solid 1px;
                line-height: 20px;
            }
            
            .l-button-search {
                width: 50px;
                margin-left: 10px;
                padding-bottom: 2px;
                display: inline;
            }
            
            .txt_sp {
                width: 90px;
                display: inline-block;
            }
            
            .d_sp {
                margin: 20px 30px;
            }
            
            body {
            }
        </style>
        <script type="text/javascript">
           
        </script>
    </head>
    <body style="padding:6px; overflow:hidden;">
        <div id="">
            <!-- 收款结算单 -->
            <form name="Form1" method="post" action="purcherTypeSave.do" id="Form1">
                <div>
                    <div class="d_sp">
                        <span class="txt_sp"><font color="red">*</font>单据类型：</span>
                        <select id="purchaseType" name="purchaseType"  class="l-textarea" validate="{required:true}" width="30%">
                            <option value="1">退货单</option>
                            <option value="2">采购单</option>
                        </select>
                    </div>
                    <div class="d_sp">
                        <span class="txt_sp"><font color="red">*</font>单据有效期：</span>
                        <input type="text" id="periodValidity"  class="l-textarea" maxlength="8"  name="periodValidity" validate="{required:true,positiveInteger:true}" >&nbsp;&nbsp;&nbsp;天
                    </div>
                  <div class="d_sp">
                    <table cellpadding="0" cellspacing="0" class="l-table-edit p-tab"" >
                    <tr>
				    <td><input type="submit" value="设置" id="submit1" style="font-size: 12px;" class="l-button l-button-submit"/></td>
				    <td>&nbsp;&nbsp;&nbsp;</td>
				    <td ><input type="button" value="取消" name="tests"  style="font-size: 12px;" id="tests" class="l-button l-button-test" /></td>
			        </tr>
                     </table>
                    </div>
                    
                </div>
            </form><!-- 采购单-->
            <div>
                <div id="div_before" />
            </div>
            <script type="text/javascript">
            	
   var basePath ="${BasePath}";
	$(function() {
		//validate
		$.metadata.setType("attr", "validate");
		var v = $("form").validate(
				{
					errorPlacement : function(lable, element) {
						lable.ligerHideTip();
						if (element.hasClass("l-textarea")) {
							element.ligerTip({
								content : lable.html(),
								target : element[0]
							});
						} else if (element.hasClass("l-text-field")) {
							element.parent().ligerTip({
								content : lable.html(),
								target : element[0]
							});
						} else {
							lable.appendTo(element.parents("td:first").next(
									"td"));
						}
					},
					success: function (lable)
			        {
			            lable.ligerHideTip();
			            lable.remove();
			        },
			        submitHandler : function() {
			        	var periodvalidity = $("#periodvalidity").val();
			    		if(periodvalidity == ''){
			    			alert("请输入有效期");
			    			return false;
			    		}
						$("form .l-text,.l-textarea").ligerHideTip();
						var options = {
							type : 'POST',
							
							success : function(data) {
								if (data == "success") {
									window.parent.f_tip('新增成功');
									window.location.href= basePath+ "/suppliers/suppcontral/purcherType.do";
								} else {
									window.parent.f_tip('你选择的类型已经存在');
								}
							}
						}, $form1 = $("#Form1");
						$form1.ajaxSubmit(options);
						return false;
					}
				});
	       });
				
            	$(function(){
						
					grid1 = $("#div_before").ligerGrid({
						columns: 
						[{
							name: 'purchaseType',
							display: '单据类型',
							render: function(rowdata, index, value){
								if (value == 1) {
									return '退货单';
								}
								else 
									if (value == 2) {
										return '采购单';
									}
									
									else {
										return '';
									}
							}
							
						}, 
						
						{
							name: 'periodValidity',
							display: '有效期'
						},	
						{ display: '操作', isSort: false, render: function (rowdata, rowindex, value){
			        	    var h = "";
			        	    h += "<a href='javascript:updateReceipts(" + rowindex + ")'>修改</a> ";
			               return h;
			           	}
			           }
						
						],
						url: "ajaxpurcherType.do",
						width: '50%',
						dataType: 'server',
						dataAction: 'server'
						//pagesizeParmName: 'pageSize'
					});	
				});	
            	
                function updateReceipts(rowindex){
                 	  var cid=grid1.getData()[rowindex].id;
                 	  var m=$.ligerDialog.open({title:'修改单据有效设置',url:basePath+'/suppliers/suppcontral/toUpdateReceipts.do?id='+cid,height:350,width:600,isResize: false, isDrag: false });
                 	  m.show(); 
                }
                
                // 取消
                $("#tests").click(function() {
               	close_liger_tab();
               });	
            	
            </script>
        </div>
    </body>
</html>
